//
//  TabBarViewController.m
//  云音乐
//
//  Created by lanou3g on 15/6/4.
//  Copyright (c) 2015年 C205. All rights reserved.
//
// RGB颜色
#define YQColor(r, g, b ,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

// 随机色
#define YQRandomColor YQColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256),1.0)

#import "TabBarViewController.h"
#import "RDVTabBar.h"
#import "RDVTabBarItem.h"
#import "C205AccountViewController.h"
#import "C205FriendsViewController.h"
#import "C205MyMusicViewController.h"
#import "C205DisCoverViewController.h"
@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    C205DisCoverViewController * dis  = [[C205DisCoverViewController alloc]init];
    C205FriendsViewController * friend = [[C205FriendsViewController alloc]init];
    C205AccountViewController * account = [[C205AccountViewController alloc]init];
    C205MyMusicViewController * myMusic = [[C205MyMusicViewController alloc]init];
    
    UIViewController *disNa = [[UINavigationController alloc]
                               initWithRootViewController:dis];
    UIViewController *friendNa = [[UINavigationController alloc]
                                  initWithRootViewController:friend];
    UIViewController *accountNa = [[UINavigationController alloc]
                                   initWithRootViewController:account];
    UIViewController *myMusicNA = [[UINavigationController alloc]
                                   initWithRootViewController:myMusic];
    
    
    [self setViewControllers:@[disNa,myMusicNA,friendNa,accountNa]];
    [disNa.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"cm2_topbar_bg"]forBarMetrics:0];
    
    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = YQColor(248, 249, 246, 1.0);
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = YQColor(255, 255, 255,1.0);
    
    NSArray *tabBarItemImages = @[@"cm2_btm_icn_discovery", @"cm2_btm_icn_music", @"cm2_btm_icn_friend",@"cm2_btm_icn_account"];
    
    NSArray * titleArray = @[@"发现音乐",@"我的音乐",@"朋友",@"账号"];
    
    
    RDVTabBar *tabBar = [self tabBar];
    UIImageView * image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cm2_btm_tab_left_prs"]];
    [tabBar setFrame:CGRectMake(CGRectGetMinX(tabBar.frame), CGRectGetMinY(tabBar.frame), CGRectGetWidth(tabBar.frame), 49)];
    image.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 49);
    
    [tabBar.backgroundView addSubview:image];
    
    for (int i = 0;  i < 4;  i++) {
        RDVTabBarItem * item = [[self tabBar].items objectAtIndex:i];
        if (i < 2) {
            [item setBackgroundSelectedImage:[UIImage imageNamed:@"cm2_blk_left_check"] withUnselectedImage:nil];
        }else
        {
            [item setBackgroundSelectedImage:[UIImage imageNamed:@"cm2_blk_left_check"] withUnselectedImage:nil];
        }
        UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_prs",
                                                      [tabBarItemImages objectAtIndex:i]]];
        UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[tabBarItemImages objectAtIndex:i]]];
        item.title = [titleArray objectAtIndex:i];
        item.selectedTitleAttributes = selectTextAttrs;
        item.unselectedTitleAttributes = textAttrs;
        [item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
